import { generalRequest } from "../services/genServ";
import {
   type DataResponse,
} from "../models/general";
import {
    type Session,TrainingSession, ChatMessage
 } from "../models/debate";
 import type {  } from '../models/debate';



// 创建会话后台数据请求方法
export function createSession(data: Object): Promise<Session> {
    const res = generalRequest("/api/debates/", {
        method: 'POST',
        data
    });
    return res as Promise<Session>;
}

export function getAIResponse(data:Object):Promise<DataResponse>{
    const res =generalRequest("/api/debates/getAIResponse",{
        method: 'POST',
        data 
        /*
        userId:用户ID
        sessionId:会话ID
        */
    })
    return res as Promise<DataResponse>//返回结果：此次AI生成的语句
}

export function sendUserResponse(data:Object):Promise<DataResponse>{
    const res=generalRequest("/api/debates/sendUserResponse",{
        method: 'POST',
        data
        /*
        userId:用户ID
        sessionId:会话ID,
        userResponse:用户此次的回答
        */ 
    }) 
    return res as Promise<DataResponse>
}


// 获取辩论历史记录
export function getDebateHistory(): Promise<DataResponse> {
    const res = generalRequest("/api/debates/history", {
        method: 'GET'
    });
    return res as Promise<DataResponse>;
}

// 获取培训历史记录
export function getTrainingHistory(): Promise<TrainingSession[]> {
    const res = generalRequest("/api/trainings/history", {
        method: 'GET'
    });
    return res as Promise<TrainingSession[]>;
}

// 获取会话消息
export function getSessionMessages(sessionId: string): Promise<DataResponse> {
    const res = generalRequest(`/api/debates/${sessionId}/messages`, {
        method: 'GET'
    });
    return res as Promise<DataResponse>;
}

// 获取单个辩论会话详情
export function getDebateDetail(sessionId: string): Promise<Session> {
    const res = generalRequest(`/api/debates/${sessionId}`, {
        method: 'GET'
    });
    return res as Promise<Session>;
}

// 获取单个培训会话详情
export function getTrainingDetail(sessionId: string): Promise<TrainingSession> {
    const res = generalRequest(`/api/trainings/${sessionId}`, {
        method: 'GET'
    });
    return res as Promise<TrainingSession>;
}

// 删除辩论会话
export function deleteDebateSession(sessionId: string): Promise<any> {
    const res = generalRequest(`/api/debates/${sessionId}`, {
        method: 'DELETE'
    });
    return res;
}

// 删除培训会话
export function deleteTrainingSession(sessionId: string): Promise<any> {
    const res = generalRequest(`/api/trainings/${sessionId}`, {
        method: 'DELETE'
    });
    return res;
}
